package day21.pack7;

public class Test2 {
    public static void main(String[] args) throws InterruptedException {
        Runnable r = () -> {
            while (true) {
                System.out.println(Thread.currentThread().getName() + "1");
                System.out.println(Thread.currentThread().getName() + "2");
                System.out.println(Thread.currentThread().getName() + "3");
                if(Thread.currentThread().isInterrupted()) break;
            }
        };
        Thread t1 = new Thread(r, "A");
        t1.setDaemon(false);
        t1.start();
//        t1.stop(); 暴力停止，不建议，任务做一半被嘎了，风险不可控
//        t1.interrupt(); // 把线程的isInterrupted()设置为true
        // 通过编程的方式，让程序员去合理的安全的退出线程
    }
}
